package com.tao.controller.webpageController;

import com.tao.pojo.dto.CategoryDto;
import com.tao.pojo.dto.PageSelectCategoryDto;
import com.tao.pojo.entity.Product;
import com.tao.result.PageResult;
import com.tao.result.Result;
import com.tao.service.CategoryService;
import com.tao.service.ProductService;
import com.tao.service.impl.CategoryService1;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.GetExchange;

import java.util.List;

@CrossOrigin(origins = "http://localhost:7000/")
@RestController
@Slf4j
@RequestMapping("/webPage/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    ProductService productService;

    @PostMapping("/add")
    public Result addCategoryController(@RequestBody CategoryDto categoryDto){
        log.info("addCategoryController接收到前端数据categoryDto：{}",categoryDto);
        categoryService.addCategoryService(categoryDto);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result deleteCategoryController(Integer  id){
        log.info("deleteCategoryController接收到前端参数id:{}",id);
        categoryService.deleteCategoryService(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result updateCategoryControler(@RequestBody CategoryDto categoryDto){
        log.info("updateCategoryControler接收到前端数据categoryDto：{}",categoryDto);
        categoryService.updateCategoryService(categoryDto);
        return Result.success();
    }

    @GetMapping("/pageSelect")
    public Result pageSelectCategoryController(PageSelectCategoryDto pageSelectCategoryDto){
        PageResult pageResult=categoryService.pageSelectCategoryService(pageSelectCategoryDto);
        return Result.success(pageResult);
    }

    @GetMapping("/selectByType")
    public Result selectCategoryByTypeController(Integer type){
        log.info("前端传来的type:{}",type);
        return Result.success(categoryService.selectCategoryByTypeService(type));

    }

    @PostMapping("/status/{status}")
    public Result updateStatusController(@PathVariable Integer status,Integer id){
        categoryService.updateStatusService(status,id);
        return Result.success();
    }

    @GetMapping("/selectById")
    public Result selectById(Integer id){
        return Result.success(categoryService.selectCategoryById(id));
    }
}
